﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace com.lover.astd.common.model.building
{
    public class Building : AsObject
    {
        private int _buildingId;
        /// <summary>
        /// 用户所有建筑中该建筑的序号
        /// </summary>
        public int BuildingId
        {
            get { return _buildingId; }
            set { _buildingId = value; }
        }
        private bool _isOutCity;
        /// <summary>
        /// 是否是外城建筑
        /// </summary>
        public bool IsOutCity
        {
            get { return _isOutCity; }
            set { _isOutCity = value; }
        }
        private int _level;

        public int Level
        {
            get { return _level; }
            set { _level = value; }
        }
        private int _upgradeCost;
        /// <summary>
        /// 如果是外城, 消耗为玉石, 否则为银币
        /// </summary>
        public int UpgradeCost
        {
            get { return _upgradeCost; }
            set { _upgradeCost = value; }
        }
        /// <summary>
        /// 获取消耗的字符串表示
        /// </summary>
        /// <returns></returns>
        public string getCost() { if (IsOutCity) return String.Format("{0}玉石", UpgradeCost); else return String.Format("{0}银币", UpgradeCost); }
        private int _cdtime;
        /// <summary>
        /// CD时间, 单位:秒
        /// </summary>
        public int Cdtime
        {
            get { return _cdtime; }
            set { _cdtime = value; }
        }
        public void fillValues(XmlNodeList nodes)
        {
            foreach (XmlNode node in nodes)
            {
                if (node.Name == "id") this.Id = Int32.Parse(node.InnerText);
                else if (node.Name == "buildid") this.BuildingId = Int32.Parse(node.InnerText);
                else if (node.Name == "buildname") this.Name = node.InnerText;
                else if (node.Name == "buildlevel") this.Level = Int32.Parse(node.InnerText);
                else if (node.Name == "nextcopper")
                {
                    this.UpgradeCost = Int32.Parse(node.InnerText);
                    this.IsOutCity = false;
                }
                else if (node.Name == "nextstone")
                {
                    this.UpgradeCost = Int32.Parse(node.InnerText);
                    this.IsOutCity = true;
                }
                else if (node.Name == "cdtime") this.Cdtime = Int32.Parse(node.InnerText);
            }
        }
    }
}
